package com.tuo.service.impl;

import com.tuo.beans.Detail;
import com.tuo.beans.Orders;
import com.tuo.service.DetailService;
import com.tuo.service.OrderService;
import com.tuo.util.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tuo on 2016/1/9.
 */
@Service
public class OrderServiceImpl extends BaseServiceImpl<Orders> implements OrderService {
    @Autowired
    DetailService detailService;

    @Override
    public void save(Orders orders) {
        try {
            super.save(orders);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        if (orders.getDetails() == null || orders.getDetails().size() == 0) {
            return;
        }
        for (Detail detail : orders.getDetails()) {
            detail.setOrdId(orders.getId());
            try {
                this.detailService.save(detail);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    }
}
